package com.xiaojiu.mvp.contract;

import com.xiaojiu.bean.PuBuLiuModel;
import com.xiaojiu.mvp.view.ErrorView;
import com.xiaojiu.nohttp.IRequestRx;

import rx.Observable;

/**
 * Created by Jacky on 2017/2/4.
 */

public class LoginContract {
    public interface View extends ErrorView {
        /**
         * 登陆
         *
         * @param result
         */
        void onLogin(PuBuLiuModel result);

        /**
         * 注册
         *
         * @param result
         */
        void onRegister(PuBuLiuModel result);

        /**
         * 获取验证
         *
         * @param result
         */
        void onVerification(PuBuLiuModel result);
    }

    public interface Model {
        /**
         * 登陆
         *
         * @param account 账号
         * @param pass    密码
         * @return
         */
        Observable<PuBuLiuModel> getLogin(String account, String pass);

        /**
         * 注册
         *
         * @param account 账号
         * @param pass    密码
         * @return
         */
        Observable<PuBuLiuModel> getRegister(String account, String pass);

        /**
         * 验证码
         *
         * @param account 账号
         * @param pass    密码
         * @return
         */
        Observable<PuBuLiuModel> getVerification(String account, String pass);
    }

    public static class LoginModelImpl implements Model {
        /**
         * 登陆
         *
         * @param account 账号
         * @param pass    密码
         * @return
         */
        @Override
        public Observable<PuBuLiuModel> getLogin(String account, String pass) {


            String mUrl = "http://image.baidu.com/channel/listjson?pn=" + 1
                    + "&rn=" + 22
                    + "&tag1=%E6%98%8E%E6%98%9F&tag2=%E5%85%A8%E9%83%A8";
            return IRequestRx.get(mUrl)
                    .execute(PuBuLiuModel.class);
        }

        /**
         * 注册
         *
         * @param account 账号
         * @param pass    密码
         * @return
         */
        @Override
        public Observable<PuBuLiuModel> getRegister(String account, String pass) {
            String mUrl = "http://image.baidu.com/channel/listjson?pn=" + 1
                    + "&rn=" + 22
                    + "&tag1=%E6%98%8E%E6%98%9F&tag2=%E5%85%A8%E9%83%A8";

            return IRequestRx.get(mUrl)
                    .execute(PuBuLiuModel.class);
        }

        /**
         * 验证码
         *
         * @param account 账号
         * @param pass    密码
         * @return
         */
        @Override
        public Observable<PuBuLiuModel> getVerification(String account, String pass) {
            String mUrl = "http://image.baidu.com/channel/listjson?pn=" + 1
                    + "&rn=" + 22
                    + "&tag1=%E6%98%8E%E6%98%9F&tag2=%E5%85%A8%E9%83%A8";
            return IRequestRx.get(mUrl)
                    .execute(PuBuLiuModel.class);
        }
    }


}